<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page deferredSyntaxAllowedAsLiteral="true" %>
<!DOCTYPE html>
<html>
<head>
    <base href="${pageContext.request.contextPath}/"/>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="Css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css" href="Css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="Css/style.css"/>
    <script type="text/javascript" src="Js/jquery.js"></script>
    <script type="text/javascript" src="Js/bootstrap.js"></script>
    <script type="text/javascript" src="Js/ckform.js"></script>
    <script type="text/javascript" src="Js/common.js"></script>
    <link href="layui/css/layui.css" rel="stylesheet"/>
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media ( max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
</head>
<body>
<form action="" method="post" class="definewidth m20">
    <table class="table table-bordered table-hover ">
        <tr>
            <td width="10%" class="tableleft">编号</td>
            <td><input type="text" id="id" name="id" value="${edit.id}" readonly="readonly"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">姓名</td>
            <td><input type="text" id="username" name="username" value="${edit.username}" readonly="readonly"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">权限名称</td>
            <td>
                <select id="level" name="level">
                    <c:forEach items="${roles}" var="role">
                        <option value="${role.id}"
                                <c:if test="${role.id==edit.level}">selected</c:if>>${role.rolename}</option>
                    </c:forEach>
                </select>
            </td>
        </tr>
        <tr>
            <td class="tableleft"></td>
            <td>
                <input type="button" class="btn btn-info" value="提交" id="submit"/>
                <button type="button" class="btn btn-success" name="backid" id="backid">返回列表</button>
            </td>
        </tr>
    </table>
</form>
</body>
</html>
<!--引入你自己的layui文件-->
<script src="layui/layui.js"></script>
<%--<!--xtree的js文件-->--%>
<%--<script src="assets/layui-xtree/layui-xtree.js"></script>--%>
<script type="text/javascript">
    $("#backid").click(function () {
        window.location.href = "/role/index";
    });
    $("#submit").click(function () {
        var id = '';
        id = ${edit.id};
        var level = $("#level").val();
        var param = "id=" + id + "&level=" + level;
        $.ajax({
            url: "/user/update",
            type: "post",
            async: true,
            data: param,
            success: function (res) {
                if (res.success) {
                    alert("修改成功！")
                    window.location.href = "/role/index";
                } else {
                    alert(res.message);
                }
            },
            error: function (e) {
                alert(e);
            }
        })
    });
</script>